package com.xinqi.modules.exam.common.manager.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xinqi.common.base.enums.YesNoNumberEnum;
import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.mybatis.data.service.impl.BaseServiceImpl;
import com.xinqi.modules.exam.common.constants.ExamI18nConstants;
import com.xinqi.modules.exam.common.domain.ClassMenuEntity;
import com.xinqi.modules.exam.common.manager.ClassMenuManager;
import com.xinqi.modules.exam.common.mapper.ClassMenuMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 课程内容表管理层实现
 *
 * @author: linkai
 * @date: 2023/07/26
 */
@Service
@RequiredArgsConstructor
public class ClassMenuManagerImpl extends BaseServiceImpl<ClassMenuMapper, ClassMenuEntity> implements ClassMenuManager {

    /**
     * 校验板块是否隐藏
     *
     * @author dzy
     */
    @Override
    public void checkShowCourseContent(Long classId) {
        LambdaQueryWrapper<ClassMenuEntity> wrapper = new LambdaQueryWrapper();
        wrapper.eq(ClassMenuEntity::getClassId, classId);
        wrapper.eq(ClassMenuEntity::getHiden, YesNoNumberEnum.NO.getCode());
        wrapper.eq(ClassMenuEntity::getType, 3); // 3：代表板块中的测评
        List<ClassMenuEntity> menuList = this.list(wrapper);
        List<Integer> types = menuList.stream().map(ClassMenuEntity::getType).collect(Collectors.toList());
        CommonErrors.NOT_DATA.check(CollectionUtil.isNotEmpty(types), ExamI18nConstants.板块不存在);
    }
}
